﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
 * Virtual Earth Screensaver
 * Keith Kinnan
 * 5/12/2007
 * 9/30/2006
-->
<html>
<head>
<title>Virtual Earth Screensaver</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="##VIRTUAL_EARTH_API_URL##"></script>
<script type="text/javascript">
var map = null;
var a = new Array();
var UPDATE_INTERVAL = null;
var SCENE_INDEX = null;
var timer = null;

try
{
   ##SCENES##
   NUM_SCENES=a.length;
   UPDATE_INTERVAL = ##UPDATE_INTERVAL##;
   SCENE_INDEX=parseInt(Math.random() * NUM_SCENES);
   timer = null;
}
catch(ex)
{
}

function EventMapLoad()
{
   map.HideDashboard();
   MoveLogo();
   setTimeout('LoadScene();',1000);
   timer = setTimeout('LoadNextScene();', UPDATE_INTERVAL);
}

function MoveLogo()
{
   var elements = document.getElementsByTagName('div');
   var logo = null;
   for( var i=0; i < elements.length; ++i)
   {
      if (elements[i].className.indexOf('PoweredByLogo') > -1)
      {
         logo = elements[i];
         break;
      }
   }
   if (logo)
   {
      logo.style.top = '0px';
   }
}

function CreateMap()
{
   try 
   {
      map = new VEMap('myMap');
      map.onLoadMap = EventMapLoad;
      var element = a[SCENE_INDEX];
      var link = a[SCENE_INDEX][0];
      var center = ExtractCenter(link);
      var level = ExtractLevel(link);
      var style = ExtractStyle(link);
      map.LoadMap(center, level, style);
   } 
   catch(ex)
   {
   }
}

function LoadPrevScene()
{
   try 
   {
      if (timer)
      {
         clearTimeout(timer);
      }
      timer = setTimeout('LoadNextScene();', UPDATE_INTERVAL);
      --SCENE_INDEX;
      if (SCENE_INDEX < 0)
      {
         SCENE_INDEX = NUM_SCENES - 1;
      }
      LoadScene();
   }
   catch(ex)
   {
   }
}

function LoadNextScene()
{
   try 
   {
      if (timer)
      {
         clearTimeout(timer);
      }
      timer = setTimeout('LoadNextScene();', UPDATE_INTERVAL);
      ++SCENE_INDEX;
      SCENE_INDEX = SCENE_INDEX % NUM_SCENES;
      LoadScene();
   } 
   catch(ex)
   {
   }
}

function LoadScene()
{
   try 
   {
      var link = a[SCENE_INDEX][0];
      var title = a[SCENE_INDEX][1];
      var descr = a[SCENE_INDEX][2];
      var center = ExtractCenter(link);
      var style = ExtractStyle(link);
      var level = ExtractLevel(link);
      var scene = ExtractScene(link);
      
      if (scene && (style == VEMapStyle.Birdseye))
      {
         map.SetBirdseyeScene(scene);
      }
      else if (style && (style != map.GetMapStyle()))
      {
         map.SetMapStyle(style);
      }
      
      if (center)
      {
         map.SetCenterClassic(center);
      }
      if (level)
      {
         map.SetZoomLevel(parseInt(level));
      }

      document.getElementById('TITLE1').innerHTML = title;
      document.getElementById('TITLE2').innerHTML = title;
      document.getElementById('DESCR1').innerHTML = descr;
      document.getElementById('DESCR2').innerHTML = descr;
      document.getElementById('URL').innerHTML = link;
   } 
   catch(ex)
   {
   }
}

function ExtractCenter(link)
{
   var ll = null;
   var regEx = /cp=[0-9A-Za-z.~-]+/;
   var strArr = link.match(regEx);
   if (strArr && strArr[0])
   {
      var llStr = strArr[0].replace(/cp=/,'');
      if (llStr.indexOf('~') > -1)
      {
         var llArray = llStr.split('~');
         ll = new VELatLong(parseFloat(llArray[0]),parseFloat(llArray[1]));
      }
      else
      {
         ll = new VELatLong();
         ll._reserved = llStr;
      }
  }
  return ll;
}

function ExtractStyle(link)
{
   var regEx = /style=[a-zA-Z]+/;
   var strArr = link.match(regEx);
   var style = null;
   if (strArr && strArr[0])
   {
      style = strArr[0].replace(/style=/,'');
   }
   return style;
}

function ExtractLevel(link)
{
   var regEx = /lvl=[0-9]+/;
   var strArr = link.match(regEx);
   var level = null;
   if (strArr && strArr[0])
   {
      level = strArr[0].replace(/lvl=/,'');
   }
   return level;
}

function ExtractScene(link)
{
   var scene=null;
   try 
   {
      var regEx = /scene=[0-9]+/;
      var strArr = link.match(regEx);
      var scene = null;
      if (strArr && strArr[0])
      {
         scene = strArr[0].replace(/scene=/,'');
      }
   } 
   catch(ex)
   {
   }
   return scene;
}
</script>
</head>
<body onload='CreateMap();' style='background-color:#000; width:100%; height:100%;'>
<div id='URL' style='display:none'>http://maps.live.com</div>
<div id='myMap' style='position:absolute; top:0px; left:0px; width:100%; height:100%;'></div>
<div id='sceneTitle' style='position:absolute; top:6px; right:10px; color:#000; z-index:100; font: normal 12px Arial; width:50%; text-align:right;'><span id='TITLE1' style='font-weight:bold;'></span><br/><span id='DESCR1'></span></div>
<div id='sceneDesc' style='position:absolute; top:5px; right:10px; color:#fff; z-index:101; font: normal 12px Arial; width:50%; text-align:right;'><span id='TITLE2' style='font-weight:bold;'></span><br/><span id='DESCR2'></span></div>
<div style='position:absolute; bottom:5px; left:10px; color:#000; z-index:101; font: normal 12px Arial; width:50%; text-align:left;'>##PRESS_ENTER##</div>
<div style='position:absolute; bottom:6px; left:10px; color:#fff; z-index:101; font: normal 12px Arial; width:50%; text-align:left;'>##PRESS_ENTER##</div>
</body>
</html>